package com.colorlight.cloud.gateway.api.message.model;

import com.colorlight.cloud.gateway.api.message.constraint.schedule.ScheduleActions;
import com.google.protobuf.ByteString;
import com.iot.proto.gateway.Gateway;
import com.iot.proto.type.ProtocolSummationType;
import lombok.*;

import java.io.Serializable;

/**
 * @author Demon
 * @date 8/1/2024  下午3:34
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Msg<T extends ScheduleActions> implements Serializable {
	private static final long serialVersionUID = 753468951753468951L;
	private Long seqId;
	private Long replySeqId;
	private T bizContent;
	private Long timestamp;
	private String version;
	private String uuid;
	private ProtocolSummationType.NameStruct nameStruct;
	
	/**
	 * 消息转为对象
	 *
	 * @param msg protobuf消息
	 * @author Demon
	 **/
	public void msgTransition(Gateway.Msg msg) {
		ByteString bizContent = msg.getBizContent() ;
		this.setSeqId(msg.getSeqId());
		this.setReplySeqId(msg.getReplySeqId());
		this.getBizContent().byteConvertObject(bizContent);
		this.setTimestamp(msg.getTimestamp());
		this.setVersion(msg.getVersion());
		this.setUuid(msg.getUuid());
		this.setNameStruct(msg.getNameStruct());
	}
}